"""
Project Name : api_automation_framework
File Name : redirect-to.py
Author : lldhsds
Date : 2024/12/29 15:24
Description: /redirect-to 302/3XX Redirects to the given URL.
"""

import requests

url = "https://httpbin.org/redirect-to"
headers = {'accept': 'text/html'}

def delete_redirect_to():
    response = requests.delete(url, headers=headers)
    print(response.status_code)
    print(response.url)
    print(response.headers)
    print(response.text)

def get_redirect_to():
    params = {'url': 'https://www.baidu.com', 'status_code': 404}
    response = requests.get(url, headers=headers, params=params)
    print(response.status_code)
    print(response.url)
    print(response.headers)
    print(response.text)


def patch_redirect_to():
    response = requests.patch(url, headers=headers)
    print(response.status_code)
    print(response.url)
    print(response.headers)
    print(response.text)


def post_redirect_to():
    headers = {"Accept": "text/html", "Content-Type": "application/x-www-form-urlencoded"}
    data = {
        'url': 'https://www.baidu.com',
        'status_code': 404
    }
    response = requests.post(url, headers=headers, data=data)
    print(response.status_code)
    print(response.url)
    print(response.headers)
    print(response.text)


def put_redirect_to():
    headers = {"Accept": "text/html", "Content-Type": "application/x-www-form-urlencoded"}
    data = {
        'url': 'https://www.baidu.com',
        'status_code': 502
    }
    response = requests.post(url, headers=headers, data=data)
    print(response.status_code)
    print(response.url)
    print(response.headers)
    print(response.text)


delete_redirect_to()
get_redirect_to()
patch_redirect_to()
post_redirect_to()
put_redirect_to()